#include "queue.hpp"

void Queue::push(Task* t) {
   const std::lock_guard<std::mutex> lock(_lock);
   tasks.push_front(t);
}

Task* Queue::pop() {
    const std::lock_guard<std::mutex> lock(_lock);
    if (!tasks.empty()) {
        Task* res = tasks.front();
        tasks.pop_front();
        return res;
    } else {
        return nullptr; 
    }
}

Task* Queue::steal() {
    const std::lock_guard<std::mutex> lock(_lock);
    if (!tasks.empty()) {
        Task* res = tasks.back();
        tasks.pop_back();
        return res;
    } else {
        return nullptr; 
    }
}

